import * as types from "@/store/mutation-types";
import { SESSION_KEY_TOKEN, LOCATION_KEY_USERDATA } from "@/config";
import {
  clearSessionStorage,
  setLocalStorage,
  clearLocalStorage,
} from "@/utils";
// 设置token
export const setToken = ({ commit }, token) => {
  setLocalStorage(SESSION_KEY_TOKEN, token);
  commit(types.SET_TOKEN, token);
};
// 设置用户数据
export const setUserData = ({ commit }, data) => {
  setLocalStorage(LOCATION_KEY_USERDATA, data);
  commit(types.SET_USERDATA, data);
};

// 设置loading
export const setLoading = ({ commit }, status) => {
  commit(types.SET_LOADING_STATUS, status);
};

// 设置顶部栏index
export const setActiveIndex = ({ commit }, index) => {
  commit(types.SET_MMENU_INDEX, index);
};
// 设置背景颜色
export const setBackColor = ({ commit }, index) => {
  commit(types.SET_BACK_COLOR, index);
};
// 设置字体颜色
export const setFontColor = ({ commit }, index) => {
  commit(types.SET_FONT_COLOR, index);
};
// 设置透明度
export const setOpacity = ({ commit }, index) => {
  commit(types.SET_OPACITY, index);
};
// 设置选中颜色
export const setHoColor = ({ commit }, index) => {
  commit(types.SET_HOCOLOR, index);
};
// 设置摩斯遮挡
export const setFilter = ({ commit }, index) => {
  commit(types.SET_FILTER, index);
};
// 设置退出按钮显示隐藏
export const setIsLogin = ({ commit }, index) => {
  commit(types.SET_IS_LOGIN, index);
};
// 顶部栏是否显示
export const setHeadShow = ({ commit }, isshow) => {
  commit(types.SET_HEAD_ISSHOW, isshow);
};
// 搜索总数据分发
export const setSearchData = ({ commit }, list) => {
  commit(types.SET_SEARCH_DATA, list);
};
// 搜索总数据条数
export const setSearchTotal = ({ commit }, list) => {
  commit(types.SET_SEARCH_TOTAL, list);
};
// 搜索值
export const setSearchValue = ({ commit }, value) => {
  commit(types.SET_SEARCH_VALUE, value);
};
// 退出登录
export const loginOut = ({ commit }) => {
  commit(types.CLEAR_TOKEN);
  commit(types.CLEAR_USERDATA);
  commit(types.SET_SEARCH_VALUE, "");
  clearLocalStorage(SESSION_KEY_TOKEN);
  clearLocalStorage(LOCATION_KEY_USERDATA);
  clearSessionStorage(SESSION_KEY_TOKEN);
};
